﻿using SenFangKaoHe_MVC.Models.Entity;
using SqlSugar;

namespace SenFangKaoHe_MVC.Services
{
    public class TiKuServices
    {
        private readonly SqlSugarClient db;
        public TiKuServices(SqlSugarClient db)
        {
            this.db = db;
        }
        public async Task<String> getTiKuMingCheng(string tkids)
        {

            int tks = tkids.Split(",").Length;
            int[] tkid = new int[tks];  //题库IDs
            for (var a = 0; a < tks; a++)
            {
                tkid[a] = Convert.ToInt32(tkids.Split(",")[a]);
            }
            String tkmc = "";
            foreach (int _tkid in tkid)
            {
                tiku _tk = await db.Queryable<tiku>()
                    .Where(tk => tk.id == _tkid)
                    .SingleAsync();
                tkmc += _tk.tikuming + ",";
            }
            return tkmc.Substring(0,tkmc.Length-1);
        }

        public async Task<tikukaoti> getTiKuKaoTi(int id)
        {
            return await db.Queryable<tikukaoti>()
                .Where(kt => kt.Id == id)
                .SingleAsync();
        }

        public async Task<tiku> getTiKu(int id)
        {
            return await db.Queryable<tiku>()
                .Where(tk => tk.id == id)
                .SingleAsync();
        }

        public async Task<List<tiku>> getTiKus()
        {
            return await db.Queryable<tiku>()
                .ToListAsync();
        }

    }
}
